<template>
	<view class="container-8989" @touchmove.stop.prevent>
		<view class="container-566"></view>
		<view class="content-12" ref="comtemt">
			<view class="title-box">
				<!-- <view class="imgview">取消</view> -->
				<view class="item">
					<view class="text">切换门店</view>
				</view>
				<image @focus="inputBindFocus" class="image-close" src="../static/image/close1.png" mode=""
					@click.stop="handleClose">
				</image>
			</view>
			<view class="content-add-uniapp">
				<view class="search">
					<view class="left">
						<image class="image-icon" src="/static/image/searchIcon.png" />
					</view>

					<view class="input-content-view">
						<input :adjust-position="false" class="uni-input" v-model="searchValue" @input="inputChange"
							placeholder-class='input-placeholder' placeholder="请输入门店编码/门店名称" />

					</view>
					<view class="clear-info-main" @click="clearInfo" v-if="clear">
						<image class="clear-info" src="../static/image/closeSearch.png" />
					</view>
					<view class="suosuo" @click="serachInfo">
						搜索
					</view>
				</view>
				<scroll-view class="store-item-content" v-if="storeList.length > 0" :scroll-y="true">
					<view class="store-item" v-for="item in storeList" :key="item.id" @click="handleStore(item)">
						<!-- <image class="store-img" :src="imgBaseUrl + item.pic" mode="widthFix" alt="" /> -->
						<view class="right">
							<view class="store-info">
								<view class="name"> 门店编码 ： {{item.code}}</view>
								<!-- <view class="name address">{{item.address }}</view> -->
								<view class="store-address">门店名称: {{item.name}}</view>
							</view>
							<view class="select-btn" :class="{active: selectedStore.id ==item.id}"></view>
						</view>
					</view>
				</scroll-view>
				<view v-show="!storeList.length">
					<template>
						<view class="klsadkl">
							<image class="store-img-empty" src="../static/image/ic_search_empty@3x.png" mode="widthFix"
								alt="" />
						</view>
					</template>
				</view>
			</view>

			<view class="class-footer  class-next">
				<view class="inset-bottom-content envent-no" v-if="storeList.length == 0">
					<text class="confirm">确认选择</text>
				</view>
				<view v-else class="inset-bottom-content" @click="confimChoose">
					<text class="confirm">确认选择</text>
				</view>

			</view>
		</view>
	</view>
</template>
<script>
	import {
		getStore
	} from '../api';
	export default {
		props: {
			index: {
				type: [Number],
			},
			storeRow: {
				type: Object
			}
		},
		data() {
			return {
				isShowName: false,
				isShowPhone: false,
				// transform: false,
				searchValue: "",
				currentStoreName: "-",
				storeList: [],
				latitude: null,
				longitude: null,
				selectedStore: {
					id: ""
				},
				clear: false,
				empty: false,
				_index: 0,
				params: {
					type: '',
					storeName: ""
				},
				windowHeight: null
			};
		},

		mounted() {
			// const windowResizeCallback = (res) => {
			// 	// console.log('变化后的窗口宽度=' + res.size.windowWidth)
			// 	console.log('变化后的窗口高度=' + res.size.windowHeight)
			// }
			// uni.onWindowResize(windowResizeCallback)
			this.selectedStore = this.storeRow
			this.getStore(this.params)

			// 监听键盘高度变化，以便设置输入框的高度

		},
		destroyed() {},
		methods: {
			async getStore(params = {
				type: '',
				storeName: ""
			}) {
				try {
					const {
						data,
						code
					} = await getStore(params)
					if (code == "000") {
						this.storeList = data
							.map(item => {
								if (item.code) {
									item.name2 = item.code + item.name
								}
								return {
									namee: item.name2,
									...item
								}
							})
					}
				} catch (e) {
					//TODO handle the exception
				}
			},
			handleClose() {
				this.$emit('close');
			},
			handleTransform() {
				// this.transform = false
			},
			handleStore(item) {
				this.selectedStore = item
			},
			inputChange(e) {
				this.searchValue = e.detail.value
				if (this.searchValue) {
					this.clear = true
				}

			},
			clearInfo() {
				this.searchValue = ''
				this.clear = false
				this.params.storeName = ""
				this.getStore(this.params)

			},
			serachInfo() {
				this.params.storeName = this.searchValue
				this.getStore(this.params)
				console.log(this.searchValue, 'this.searchValue ')
			},
			//   
			handlerIndex() {
				this.storeList.find((item, i) => {
					if (item.id == this.selectedStore.id) {
						this._index = i;
					}
				})
			},
			confimChoose() {
				this.handlerIndex()
				this.$emit('confim', {
					...this.selectedStore
				}, {
					index: this._index
				});
			},
		}
	};
</script>

<style lang="scss" scoped>
	.container-8989 {
		width: 100%;
		height: 100vh;
		display: flex;
		align-items: flex-end;
		// background: rgba(0, 0, 0, 0.7);
		position: fixed;
		left: 0;
		top: 0;
		z-index: 1000;

		.container-566 {
			position: absolute;
			height: 100%;
			width: 100%;
			background-color: rgba(0, 0, 0, .5);
			z-index: 50;
		}

		.klsadkl {
			display: flex;
			flex-direction: column;
			// justify-content: center;
			align-items: center;
			min-height: 20vh;
			filter: grayscale(1);
		}



		.store-item-content {
			max-height: 46vh;
			// border: 2rpx solid;
			background: #ffffff;
			margin-top: 20rpx;
			margin-bottom: 65Px;
			border-radius: 16rpx;

			.store-item {
				box-sizing: border-box;
				display: flex;
				align-items: center;
				padding: 16rpx;

				.store-info {
					height: 100%;
					flex: 1;
					font-size: 24rpx;
					line-height: 40rpx;

					.name {
						font-size: 28rpx;
						// font-weight: 600;
					}

					.address {
						margin-left: 10rpx;
					}

					.store-address {
						color: #999;
						// margin-top: 10px;
					}

					.time {
						color: #666;
					}

					.distance {
						margin-top: 4rpx;
					}
				}

				.right {
					width: 100%;
					height: 100%;
					display: flex;
					align-items: center;

					// border-bottom: 2rpx solid #f1f1f1;
					.select-btn {
						width: 44rpx;
						min-width: 44rpx;
						height: 44rpx;
						border-radius: center;
						border: 2rpx solid #e4e4e4;
						border-radius: 50%;
						margin-left: 40rpx;

						&.active {
							display: flex;
							justify-content: center;
							align-items: center;
							border: none;
							background-color: rgb(22, 118, 193);

							&:before {
								content: '';
								width: 8rpx;
								height: 18rpx;
								border-right: 2rpx solid #FFFFFF;
								border-bottom: 2rpx solid #FFFFFF;
								transform: rotate(45deg) translate(-2rpx);
							}
						}
					}
				}
			}

			.store-item+.store-item {
				margin-top: 18rpx;
			}
		}


		.class-next {
			background-color: #FFFFFF;
		}

		.class-footer {
			position: absolute;
			width: 100%;
			height: 108rpx;
			// bottom: constant(safe-area-inset-bottom);
			bottom: 0;
			display: flex;
			align-items: center;
			justify-content: center;

			view.envent-no {
				opacity: 0.5;
			}

			.inset-bottom-content {
				width: 626rpx;
				height: 76rpx;
				background-color: rgb(22, 118, 193);

				border-radius: 200rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				.confirm {
					font-weight: 500;
					font-size: 30rpx;
					line-height: 40rpx;
					text-align: center;
					color: #FFFFFF;
				}
			}

		}

		.content-12 {
			width: 100%;
			border-radius: 16rpx 16rpx 0 0;
			background-color: #f5f5f5;
			// height: 1062rpx;
			position: absolute;

			z-index: 51;
			// border: 2rpx solid;
			// right: -100%;
			padding-bottom: constant(safe-area-inset-bottom);
			padding-bottom: env(safe-area-inset-bottom);

			.content-add-uniapp {
				height: 100%;
				// border: 2rpx solid;
				padding: 0 24rpx;

				.search {
					margin: 0rpx 0 9rpx 0;
					width: 706rpx;
					height: 64rpx;
					background: #FFFFFF;
					border-radius: 400rpx;
					display: flex;
					align-items: center;
					position: relative;

					.left {
						margin-left: 32rpx;
					}

					.image-icon {
						width: 32rpx;
						height: 32rpx;
						vertical-align: middle;
					}

					.input-content-view {
						display: flex;
						align-items: center;
						width: 76%;

						.uni-input {
							box-sizing: border-box;
							margin-left: 16rpx;
							font-size: 28rpx;
							line-height: 40rpx;
							color: #000;
							width: 85%;
						}

						::v-deep.input-placeholder {
							font-size: 28rpx;
							line-height: 40rpx;
							color: #999999;
						}
					}

					.clear-info-main {
						display: flex;
						align-items: center;
						justify-content: center;
						position: absolute;
						right: 108rpx;
						z-index: 11;
						width: 66rpx;

						.clear-info {
							width: 44rpx;
							height: 44rpx;
						}

					}


					.suosuo {
						width: 96rpx;
						height: 56rpx;
						background-color: rgb(22, 118, 193);
						border-radius: 80rpx;
						font-size: 26rpx;
						// line-height: 40rpx;
						color: #FFFFFF;
						display: flex;
						align-items: center;
						justify-content: center;
					}
				}

			}

			.imgview {
				display: flex;
				align-items: center;
				justify-content: center;
				// transform: rotate(180deg);
				// width: 48rpx;
				height: 48rpx;

				// border: 2rpx solid;
				// &:after {
				// 	content: '';
				// 	width: 16rpx;
				// 	height: 16rpx;
				// 	border-top: 2rpx solid #999;
				// 	border-right: 2rpx solid #999;
				// 	transform: rotate(45deg);
				// 	margin: 0 8rpx;
				// }
			}
		}

		.title-box {
			display: flex;
			justify-content: space-between;
			padding: 24rpx;
			flex: 1;
			align-items: center;

			.image-close {
				width: 36rpx;
				height: 36rpx;
				vertical-align: middle;
			}

			.item {
				width: 100%;
				display: flex;
				justify-content: center;
				align-items: center;
				font-weight: 550;
				font-size: 36rpx;
				line-height: 56rpx;
				text-align: center;
				color: #333333;

				.acyive-imga-01 {
					background-position: 100% 100%;
					background-repeat: no-repeat;
					background-size: 100%;
				}
			}
		}


		.content {
			width: 100%;
			border-radius: 16rpx 16rpx 0 0;
			background-color: #f5f5f5;
			height: 1062rpx;
			position: relative;
			transform: translateX(0%);
			transition: transform ease .3s;
			padding-bottom: constant(safe-area-inset-bottom);
			padding-bottom: env(safe-area-inset-bottom);

			.content-add-uniapp {
				// border: 2rpx solid;
				padding: 0 24rpx;

				.userinfo {
					padding: 0 24rpx;
					border-radius: 16rpx;
					background: #fff;

					view.parentview {
						display: flex;
						justify-content: space-between;
					}

					.item {
						height: 88rpx;
						display: flex;
						align-items: center;
						font-size: 24rpx;
						font-weight: 600;
						border-bottom: 2rpx solid #f1f1f1;

						&:last-child {
							border-bottom: none;
						}

						.right-img-iconfont {
							display: flex;
							justify-content: center;
							align-items: center;

							.img-style {
								width: 36rpx;
								height: 36rpx;
							}
						}

						.label {
							width: 188rpx;
							font-size: 24rpx;
							line-height: 40rpx;
							color: #666666;
						}

						.leftview {
							display: flex;
							align-items: center;

							input.changnane {
								display: flex;
								height: 48rpx;
								min-height: 48rpx;
								align-items: center;
							}
						}

						.imgview {
							display: flex;
							align-items: center;
							justify-content: center;

							&:after {
								content: '';
								width: 16rpx;
								height: 16rpx;
								border-top: 2rpx solid #999;
								border-right: 2rpx solid #999;
								transform: rotate(45deg);
								margin: 0 8rpx;
							}
						}
					}
				}


				.uni-product {
					margin-top: 24rpx;
					width: 100%;
					height: 240rpx;
					// border: 2rpx solid;
					background: #FFFFFF;
					border-radius: 16rpx;

					.content-product {
						display: flex;
						// align-items: center;

						.uni-img-class {
							width: 192rpx;
							height: 192rpx
						}

						.text {
							margin-left: 16rpx;
							font-size: 28rpx;
							line-height: 40rpx;
							color: #333333;
						}

						padding: 24rpx;
					}
				}
			}



		}
	}
</style>